<?php
namespace App\Service\Admin;

class UserService extends BaseService
{
    //用户

    //游客
    public static function visitList()
    {
        $db = self::dbConn(self::$dbVisit)->where('openid', '');
        $total = $db->count();
        $res = $db->orderBy('id', 'asc')->get();
        if (!count($res)) {
            return self::toback(0, '', [], $total);
        }
        foreach ($res as &$v) {
            $v->h5code = $v->h5code ? $v->h5code : '-';
        }
        return self::toback(0, '', $res, $total);
    }

    //微信用户
    public static function wxList()
    {
        $db = self::dbConn(self::$dbWx);
        $total = $db->count();
        $res = $db->orderBy('id', 'asc')->get();
        if (!count($res)) {
            return self::toback(-2, '没有数据');
        }
        $ary = [];
        foreach ($res as $v) {
            $shequ = self::dbConn(self::$dbShequ)->where('id', $v->shequ_id)->first();
            $sq_name = $shequ ? $shequ->title : '';
            $ary[] = [
                'id' => $v->id, 'nickName' => $v->nickName,
                'avatarUrl' => $v->avatarUrl, 'openid' => $v->openid,
                'shequ_id' => $v->shequ_id, 'shequ_name' => $sq_name,
                'door' => $v->door, 'addtime' => $v->addtime,
            ];
        }
        return self::toback(0, '', $ary, $total);
    }
}